package com.hengmei.smallscreen.db.datebase
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.hengmei.smallscreen.db.dao.HistoryDao
import com.hengmei.smallscreen.db.entity.HistoricalRecord

@Database(entities = [HistoricalRecord::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
    abstract fun historyDao(): HistoryDao

    companion object{
        private  var INSTANCE:AppDatabase?=null
        //Application 调用
        fun getDatabase(context: Context):AppDatabase?{
            if(INSTANCE==null){
                INSTANCE= Room.databaseBuilder(context,AppDatabase::class.java,"hengmei.db")
                    .build()
            }
            return INSTANCE
        }
        //使用者调用
        fun getDataBase():AppDatabase?= INSTANCE
    }

}